# example.py
#
# Unpacking of tagged tuples of varying sizes

records = [
     ('foo', 1, 2),
     ('bar', 'hello'),
     ('foo', 3, 4),
]

def do_foo(x,y):
    print('foo', x, y)

def do_bar(s):
    print('bar', s)


# 序列解压方式，一般使用一个变量来接收列表中的一个元素
# 这里采取*表达式对子元素列表进行解压
for tag, *args in records:
    print("tag:",tag)
    print("args:",args)
    if tag == 'foo':
        do_foo(*args)
    elif tag == 'bar':
        do_bar(*args)
    print("=" * 20)
